package view
{
	import flash.events.Event;
	
	import model.DataProxy;
	import model.ViewProxy;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	

	public class ListViewMediator extends Mediator implements IMediator
	{ 
		public static const NAME:String 				= "ListViewMediator";
		
		private var listView:ListView;
		
		public function ListViewMediator( viewComponent:Object = null )
		{
			super( NAME, viewComponent );
		}
		
		override public function onRegister():void
		{
			listView = new ListView();
			listView.addEventListener( ListView.EXPANDED, listExpandedHandler );
			listView.init( dataProxy.vo.currentViewData, viewProxy.vo );
			
//			viewProxy.addComponent( listView );
			viewProxy.vo.listView = listView;
		}
		
		override public function listNotificationInterests():Array
		{
			return [];
		}
		
		override public function handleNotification( notification:INotification ):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			
//			switch( name )
//			{
//				case:
//					
//					break;
//			}
		}
		
		private function get dataProxy():DataProxy
		{
			return facade.retrieveProxy( DataProxy.NAME ) as DataProxy;
		}
		
		private function get viewProxy():ViewProxy
		{
			return facade.retrieveProxy( ViewProxy.NAME ) as ViewProxy;
		}
		
		private function listExpandedHandler( e:Event ):void
		{			
			switch( listView.currentData.type )
			{
				case "gallery":
					var galleryView:GalleryView = new GalleryView();
					galleryView.init( listView.currentData, viewProxy.vo );
					listView.addContent( galleryView );
				break;
			}
		}
	}
}